﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using com.tiyma.model;
using com.tiyma.components;
using com.tiyma.common;

namespace com.tiyma.web.User
{
    public partial class Index : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindYear();
            BindMonth();
            BindDay();

            BindUserInfo();
        }

        /// <summary>
        /// 绑定用户信息
        /// </summary>
        private void BindUserInfo()
        {
            if (Token == null)
                RedirectErrorPage();

            try
            {
                UserManager t_user_mgr = new UserManager();

                UserInfo t_user = t_user_mgr.GetUserInfoByUserId(Token.UserId);

                if (t_user == null)
                    RedirectErrorPage();

                txtEmail.Value = t_user.Email;
                txtNickName.Value = t_user.NickName;

                txtPhone.Value = t_user.Phone;
                txtUserName.Value = t_user.UserName;
                txtBookCount.Value = t_user.BookCount.ToString();
                if(t_user.BirthDay!=DateTime.MaxValue)
                {
                    drpYear.SelectedValue = t_user.BirthDay.Year.ToString();
                    drpMonth.SelectedValue = t_user.BirthDay.Month.ToString();
                    drpDay.SelectedValue = t_user.BirthDay.Day.ToString();
                }
              
            }
            catch (Exception ex)
            {
                LogHelper.Error("绑定用户信息失败" + ex.ToString());
                RedirectErrorPage();
            }
        }

        /// <summary>
        /// 绑定年份
        /// </summary>
        private void BindYear()
        {
            int curYear = DateTime.Now.Year;
            drpYear.Items.Add(new ListItem("选择", "-1"));
           
            for (int index = 1930; index < curYear; index++)
            {
                drpYear.Items.Add(new ListItem(index.ToString(), index.ToString()));
            }
           
        }

        /// <summary>
        /// 绑定月份
        /// </summary>
        private void BindMonth()
        {
            drpMonth.Items.Add(new ListItem("选择", "-1"));
            for (int index = 1; index < 13; index++)
            {
                drpMonth.Items.Add(new ListItem(index.ToString(), index.ToString()));
            }

           
        }

        /// <summary>
        /// 绑定天
        /// </summary>
        private void BindDay()
        {
            drpDay.Items.Add(new ListItem("选择", "-1"));
            for (int index = 1; index <= 31; index++)
            {
                drpDay.Items.Add(new ListItem(index.ToString(), index.ToString()));
            }

           
        }
    }
}
